$(document).ready(function(){
    var slides = $("#slider li");
    var slider_menu_icons = $("#slider_menu li .icon");
    var current = 0;    
    
    var timeout = window.setInterval(function(){ 
        
        var next = (current + 1) % slides.size();
        
        var z_index_current = slides.eq(current).css('z-index');
        var z_index_next = slides.eq(next).css('z-index'); 
        var class_current = '.' + slides.eq(current).attr('class');
        var class_next = '.' + slides.eq(next).attr('class'); 
        
        if( z_index_current > z_index_next ) {
             slides.eq(next).css('z-index', z_index_current);
             slides.eq(current).css('z-index', z_index_next);
        } else if ( z_index_current == z_index_next ){
            slides.eq(next).css('z-index', z_index_current);
        }

        slider_menu_icons.filter(class_current + 'active').fadeOut(2000);
        slides.eq(current).fadeOut(2000);
        slider_menu_icons.filter(class_next + 'active').fadeIn(2000);       
        slides.eq(next).fadeIn(2000);
        
        current = next;       
            
    }, 4000);
    
});


